import JSEncrypt from "jsencrypt"

// 密钥对生成 http://web.chacuo.net/netrsakeypair

const publicKey = 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC5p4GmIO1idfAXseTvIPn3nHPt\n'+
'845YmsI1gjyu4Sz8iymgK0vFG0wPRS7vsI36Bf2+EvJPcsq/AwwvD0JOb7Y74rmG\n'+
'4LK7HlmRJIGECZRpbBR76VQBQpQ1RfT7x+o2c8qERTI0PzgU9jzM3WWxDd15emtK\n'+
'fu8vhBn+e9CWnWIyYwIDAQAB'

const privateKey = 'MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBALmngaYg7WJ18Bex\n'+
'5O8g+fecc+3zjliawjWCPK7hLPyLKaArS8UbTA9FLu+wjfoF/b4S8k9yyr8DDC8P\n'+
'Qk5vtjviuYbgsrseWZEkgYQJlGlsFHvpVAFClDVF9PvH6jZzyoRFMjQ/OBT2PMzd\n'+
'ZbEN3Xl6a0p+7y+EGf570JadYjJjAgMBAAECgYBrQB1hv3vjeYZt6dL7Ye2F4dgH\n'+
'CsCc5ypyhv5PeL3oVuyBHwHyqEZUO/9VcIVUfsmLWJ6qzwHZPwV22jXP4jE/gw66\n'+
'8SLa9A3PZZzN7nqXAI1dZpavKjzU1JEQQslkpugxhocgODRkbJ2bhSFquUWZQacw\n'+
'sU0g7+P3uwseKLkzAQJBAOWHfeBGuP97sBlikDVTCaPEP/M7PX9jLu0y4I17qEu2\n'+
'D4Q3NtzkcuXBHzsOY/yf6vciWrI5r3M8jR8oRyg36kMCQQDPEKw0STK7P1VLoG36\n'+
'cTXWnmn39mBG/duvIjLlOPqc8cB3kgdedG/UzbzsmxT0Irxqq0p1OgP3n8BKtL5u\n'+
'wmVhAkAXUlwM5MK5WtT6z1P9xxEsra0dxsAp6GcFPO0qEw13m+kZsw6FBUVTaPsG\n'+
'YiDws0MJl1kF0Oyt1dI0/z+zq3LHAkBSokq2ywdt5oZ5mdqJ+agMsEeF51Lgwepr\n'+
'5+/7vlN1Up0GmsZKEZmXiUt9+R3RmBMtVpJuWeq/ZYdtyNe+h+HBAkA54uFNA2Jo\n'+
'JKyTPls1Y0CZuxhq/46+AxodJ/MH55XimK3rg50cp4GLPE+3HLUJPfUWGwcELWJC\n'+
'6MjS5xddG7cy'

// 加密
export const encrypt=(txt:string)=>{
  const encryptor = new JSEncrypt()
  encryptor.setPublicKey(publicKey) // 设置公钥
  return encryptor.encrypt(txt) // 对数据进行加密
}

// 解密
export const decrypt=(txt:string)=>{
  const encryptor = new JSEncrypt()
  encryptor.setPrivateKey(privateKey) // 设置私钥
  return encryptor.decrypt(txt) // 对数据进行解密
}